
<?php
require 'Model.php';
	class VideoModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		
		function getvideoList(){

     $sql = "select * from vv";
		    $data = $this->conn->query($sql);
			return $data;

		}


		function delvideo($id){

   	$sql = "delete from vv where vid=".$id;
			$result = $this->conn->query($sql);
			return $result;
		}

		function add1($data)
		{
			if(!empty($_FILES["pic"]["name"])){
				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
			}
			else{
				$pic='';
			}
			$video = array(
				'videoname' => $data['videoname'],  
				'tid' => $data['tid'],
				'pic'=>$pic,
				'videointro' => $data['videointro'],
				'address'=>$data['address']
				);
			$keys = implode(',',array_keys($video));
			$values = implode("','", array_values($video));
			$sql="insert into vv ({$keys}) VALUES ('{$values}')";
			var_dump($sql);
			  //执行SQL语句
			$result = $this->conn->query($sql);
			var_dump($result);
			return $result;
		}

			function getVideoByID($id){
			$sql = "select * from vv where vid=".$id;
		    $result = $this->conn->query($sql);
	      	return $result;
		}


			function update1($data)
		{
			$user = array(
				'videoname' => $data['videoname'],  
				'tid' => $data['tid'],
				'pic' => $pic,
				'videointro' => $data['videointro'],
				'address'=> $data['address']
				);
			if(!empty($_FILES["pic"]["name"])){
				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
				$user['pic'] = $pic;
			}			
			$sets = '';
			foreach ($user as $key=>$val){
				$sets.=$key."='".$val."',";
			}
			    $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
			    
			    $sql="UPDATE vv SET {$sets} where vid=".$data['id'];

			    var_dump($sql);
			  //执行SQL语句
			    $result = $this->conn->query($sql);
			    return $result;		    
			}

	}
?>